package com.example.auth.config;

import cn.hutool.core.util.ArrayUtil;
import com.example.starter.security.configure.SecurityProperties;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

/**
 * @author 王令
 * @since 2022/8/9 21:06
 */
@Configuration
@RequiredArgsConstructor
public class OAuth2ResourceConfiguration extends ResourceServerConfigurerAdapter {

    private final SecurityProperties properties;

    @SneakyThrows
    @Override
    public void configure(HttpSecurity http) {
        http
                .authorizeRequests()
                .antMatchers(ArrayUtil.toArray(properties.getPermitUrls(), String.class)).permitAll()
                .anyRequest().authenticated();
    }

}
